package cn.tqfeiyang.springplus.framework.response;

/**
 * REST API 响应码
 *
 * @author tqfeiyang
 * @since 2022-3-16
 */
public enum ResultCode {

    SUCCESS(2000, "操作成功"),

    FAILED(5000, "操作失败"),

    URL_NOT_FOUND(5001, "网址不存在"),

    ARG_NOT_VALID(5002, "请求参数错误"),

    ARG_MISSING(5003, "缺少请求参数"),

    ARG_VALIDATION_ERROR(5004, "参数验证错误"),

    ARG_TYPE_ERROR(5005, "参数类型错误"),

    NOT_LOGIN(5010, "用户没有登录"),

    LOGIN_ERROR(5011, "用户登录错误"),

    ACCESS_DENIED(5012, "存取被拒绝"),

    TOKEN_ERROR(5013, "token错误"),

    TOKEN_EXPIRED(5014, "token过期"),

    ENTITY_ID_INVALID(5020, "无效的id"),

    ENTITY_NOT_EXISTS(5021, "数据不存在"),

    ENTITY_INSERT_ERROR(5022, "数据新增失败"),

    ENTITY_UPDATE_ERROR(5023, "数据更新失败"),

    ENTITY_DELETE_ERROR(5024, "数据删除失败");

    private final int code;

    private final String message;

    ResultCode(final int code, final String message) {
        this.code = code;
        this.message = message;
    }

    public static ResultCode getApiCode(int code) {
        ResultCode[] resultCodes = ResultCode.values();
        for (ResultCode resultCode : resultCodes) {
            if (resultCode.getCode() == code) {
                return resultCode;
            }
        }
        return FAILED;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

}
